package cn.lbwfree.day3_12;

import java.math.BigInteger;
import java.util.Scanner;

/**
 * @date:2020年3月12日
 * @author:lbwfree
 * @number:BASIC-12 十六进制转八进制
 */
public class Binary_conversion {
	public static void main(String[] args) {
		Scanner inScanner = new Scanner(System.in);
		
		// num 个楼进制
		int num =inScanner.nextInt();
		int label = 0;
		if(num>10||num<1)
		{
			return ;
		}
		String[] numStrings = new String[num];
		BigInteger[] integers = new BigInteger[num];
		for (int i = 0; i <num; i++) {
			numStrings[i]=inScanner.next();
			if(numStrings[i].length()>100000)
			{
				break;
			}
			//十六进制转成十进制
			integers[i]=new BigInteger(numStrings[i], 16);
			label++;
		}
		for (int i = 0; i <label; i++) {
			//十进制转八进制
			System.out.println(integers[i].toString(8));
		}	
	}
}
